
import types from '@/store/mutation-types';
import { risBlackListBehaviorLevelApi } from '@/services/api/risk';
import { getUserLevelList } from '@/services/api/userLevel';

const risk = {
  state: {
    levelList: [],
    userLevelList: [],
    count: 0,
  },

  mutations: {
    [types.GET_LEVEL_LIST](state, data) {
      if (data && !_.isNull(data)) {
        state.levelList = data;
      }
    },
    [types.GET_USER_LEVEL_LIST](state, data) {
      if (data && !_.isNull(data)) {
        state.userLevelList = data;
      }
    },
    [types.GET_BLACK_COUNT](state, data) {
      state.count = data;
    },
  },

  actions: {
    async [types.GET_LEVEL_LIST]({ commit }) {
      const [result, data] = await risBlackListBehaviorLevelApi();
      if (result) {
        commit(types.GET_LEVEL_LIST, data);
      }
      return { result, data };
    },
    async [types.GET_USER_LEVEL_LIST]({ commit }) {
      const [result, data] = await getUserLevelList();
      if (result) {
        commit(types.GET_USER_LEVEL_LIST, data);
      }
      return { result, data };
    },
  },

};


export default risk;
